package com.shumm.controller;

import com.shumm.common.Result;
import com.shumm.po.ClassicFormula;
import com.shumm.service.ClassicFormulaService;
import jakarta.servlet.ServletException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController
@RequestMapping("/cf")
public class ClassicFormulaController{
    @Autowired
    @Qualifier("cfService")
    private ClassicFormulaService service;


    @PostMapping("/add")
    private Result add(@RequestBody ClassicFormula cf) throws IOException {
        return service.add(cf);
    }
    @PostMapping("/delete")
    private Result delete(@PathVariable(value = "id") int id) throws IOException {
        return service.delete(id);
    }

    @PostMapping("update")
    private Result update(@RequestBody ClassicFormula cf) throws IOException {
        return service.update(cf);
    }

    @PostMapping("selectById")
    private Result selectById(@PathVariable(value = "id") int id) throws IOException {
        return service.selectById(id);

    }

    @PostMapping("selectAll")
    private Result selectAll() throws ServletException, IOException {
        return service.selectAll();
    }

    @PostMapping("selectByName")
    private Result selectByName(@PathVariable(value="name") String name) throws IOException {
        return service.selectByName(name);
    }

    @PostMapping("selectByName")
    private Result selectByAlias(@PathVariable(value="alias") String alias){
        return service.selectByAlias(alias);
    }

    @PostMapping("selectByChineseMedicine")
    private Result selectByChineseMedicine(@PathVariable(value="cm") String cm){
        return service.selectByChineseMedicine(cm);

    }

    @PostMapping("selectComById")
    private Result selectComById(@PathVariable(value = "id") int id) throws IOException {
        return service.selectComById(id);
    }
}
